package com.it.zhangjun.design.pattern.statePattern;

/**
 * @className: Context
 * @description: 上下文环境
 * @author: z00018123
 * @date: 2021/4/29
 **/
public class Context {

    /**
     * 所有汽车状态
     */
    public static final OpenState openState = new OpenState();
    public static final CloseState closeState = new CloseState();
    public static final RunState runState = new RunState();
    public static final StopState stopState = new StopState();

    /**
     * 当前汽车状态
     */
    private CarState carState;

    public CarState getCarState() {
        return carState;
    }

    public void setCarState(CarState carState) {
        this.carState = carState;
        this.carState.context.setCarState(carState);
    }

    /**
     * 汽车开门
     */
    public void open() {
        this.carState.open();
    }

    /**
     * 汽车关门
     */
    public void close() {
        this.carState.close();
    }

    /**
     * 汽车飞奔
     */
    public void run() {
        this.carState.run();
    }

    /**
     * 汽车停止
     */
    public void stop() {
        this.carState.stop();
    }
}
